package com.example.demo.service;

import com.example.demo.config.StemAPI;
import com.example.demo.dto.request.exam.AddExamRequest;
import com.example.demo.dto.request.exam.GetStemsFromFeign;
import com.example.demo.dto.response.feign.FeignResponse;
import com.example.demo.dto.response.feign.GetStemsResponse;
import feign.Feign;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.springframework.stereotype.Service;

/**
 * @Author hxh
 * @Date 2020-09-16 12:52
 * @Descrption TODO
 */
@Service
public class FeignService {

    public FeignResponse getResponse(String stemId){
        StemAPI stem = Feign.builder()
                .decoder(new JacksonDecoder())
                .target(StemAPI.class,"http://112.74.105.17:20003/question-bank");
        FeignResponse response = stem.get(stemId);
        return response;
    }

    public GetStemsResponse getStems(AddExamRequest request){
        StemAPI stem = Feign.builder()
                .encoder(new JacksonEncoder())
                .decoder(new JacksonDecoder())
                .target(StemAPI.class,"http://112.74.105.17:20003/question-bank");
        GetStemsFromFeign getStem = new GetStemsFromFeign(request);
        GetStemsResponse response = stem.getStems(getStem);
        return  response;
    }
}
